#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 1e5+2;

const int b1 = 31;
const int b2 = 29;
const int mod = 1e9+7;

string s[3];
bool visit[3];
int arr[3];
size_t ans = 1e6;

int nex[N];

inline void getNex(string s){
    int j=-1,i=0;
    nex[0] = -1;
    while(s[i]!='\0'){
        if(j<0||s[i]==s[j]){
            ++i;
            ++j;
            nex[i] = j;
        }else{
            j = nex[j];
        }
    }
}

inline bool kmp(string s1, string s2){
    int i=0,j=0;
    while(s1[i]!='\0'){
        if(j<0||s1[i]==s2[j]){
            ++i;
            ++j;
            if(s2[j]=='\0') return true;
        }else{
            j = nex[j];
        }
    }
    return false;
}

inline LL qpow(int b,int n){
    LL res = 1;
    LL base = b;
    while(n){
        if(n&1){
            res = res*base%mod;
        }
        base = base*base%mod;
        n >>= 1;
    }
    return res;
}

inline string match(string s1,string s2){
    if(s1.length()>=s2.length()){
        getNex(s2);
        if(kmp(s1,s2)) return s1;
    }
    string ss = s2+"@"+s1;
    getNex(ss);
    int ch = nex[ss.length()];
    string sa = s1.substr(0,s1.length()-ch)+s2;
    return sa;
}

inline void solve(){
    string s12 = match(s[0],s[1]);
    string s3 = match(s12,s[2]);
    ans = min(ans, s3.length());
}

void dfs(int idx){
    if(idx==3){
        solve();
        return;
    }
    for(int i=0;i<3;i++){
        if(!visit[i]){
            visit[i] = true;
            arr[idx] = i;
            dfs(idx+1);
        }
    }
}

int main(){
    cin>>s[0]>>s[1]>>s[2];
    memset(visit,0,sizeof(visit));
    dfs(0);
    cout<<ans<<"\n";
    return 0;
}